import { ProTableColumn } from '@/components/pro-table/type'
import { NButton, NPopconfirm } from 'naive-ui'
import { InStoreModel } from '@/api/model/asset-management/asset-in-store-model'

type Props = {
  handleEditInStore: (row: InStoreModel) => void
  fetchDelInStore: (id: number) => void
}

export const useInStoreProTable = ({
  handleEditInStore,
  fetchDelInStore
}: Props) => {
  const columns: ProTableColumn<InStoreModel>[] = [
    {
      title: '入库单名称',
      key: 'inStoreName',
      query: {
        type: 'input'
      }
    },
    {
      type: 'tag',
      title: '入库类型',
      key: 'inStoreType',
      dictOptions: useDictData('IN_STORE_TYPE').value,
      query: {
        type: 'select',
        dictOptions: useDictData('IN_STORE_TYPE').value
      }
    },
    {
      title: '入库日期',
      key: 'inStoreDate'
    },
    {
      title: '采购名称',
      key: 'purchaseName',
      query: {
        type: 'input'
      }
    },
    {
      title: '总入库数量',
      key: 'inStoreNumber'
    },
    {
      title: '操作',
      key: 'operation',
      render(row) {
        return (
          <>
            <NButton
              type="primary"
              size="small"
              onClick={() => handleEditInStore(row)}
              quaternary
            >
              详情
            </NButton>
            <NPopconfirm onPositiveClick={() => fetchDelInStore(row.id)}>
              {{
                trigger: () => (
                  <NButton size="small" type="error" quaternary>
                    删除
                  </NButton>
                ),
                default: () => '您确定要删除？'
              }}
            </NPopconfirm>
          </>
        )
      }
    }
  ]

  return {
    columns
  }
}
